import { IFeidaoAiBrowserComponent } from '@feidao/web/interfaces';
import nodejs from '@feidao/web/atom/nodejs/msg-b/nodejs';
import render from '@feidao/web/atom/browser/render/render';
import P01 from './P01';

export default async function (fd: IFeidaoAiBrowserComponent, ...args: any[]) {
	console.log('refresh tab');
	let curr_content_node: any = null, new_content_node: any = null;
	if (fd.data.tab == "tab1") {
		const res = await nodejs(fd.data.spaceid, "teach_staff_find", {
			criteria: { staff_number: fd.data.staff_number },
			page_no: 1,
			page_size: 1
		});
		const d = res.dataArray[0];
		d.depts = await nodejs("hr_manage", "dept_find", { filter: {}, page_size: 0 });
		console.log(d);
		render(fd, d, P01, 'P01', 'inner');
		curr_content_node = fd.data.node.querySelector("#" + fd.data.content) as HTMLElement;
		curr_content_node.classList.add('display-n');
		new_content_node = fd.data.node.querySelector("#c1") as HTMLElement;
		curr_content_node.classList.remove('display-n');
		fd.data.content = 'c1';
	} else if (fd.data.tab == "tab2") {
		const res = await nodejs(fd.data.spaceid, "teach_staff_find", {
			criteria: { staff_number: fd.data.staff_number },
			page_no: 1,
			page_size: 1
		});
		const d = res.dataArray[0];
		d.depts = fd.data.depts;
		render(fd, d, P01, 'P01', 'inner');
		curr_content_node = fd.data.node.querySelector("#" + fd.data.content) as HTMLElement;
		curr_content_node.classList.add('display-n');
		new_content_node = fd.data.node.querySelector("#c2") as HTMLElement;
		curr_content_node.classList.remove('display-n');
		fd.data.content = 'c2';
	} else if (fd.data.tab == "tab3") {
		const res = await nodejs(fd.data.spaceid, "teach_staff_find", {
			criteria: { staff_number: fd.data.staff_number },
			page_no: 1,
			page_size: 1
		});
		const d = res.dataArray[0];
		d.depts = fd.data.depts;
		render(fd, d, P01, 'P01', 'inner');
		curr_content_node = fd.data.node.querySelector("#" + fd.data.content) as HTMLElement;
		curr_content_node.classList.add('display-n');
		new_content_node = fd.data.node.querySelector("#c3") as HTMLElement;
		curr_content_node.classList.remove('display-n');
		fd.data.content = 'c3';
	} else if (fd.data.tab == "tab4") {
		const res = await nodejs(fd.data.spaceid, "teach_staff_find", {
			criteria: { staff_number: fd.data.staff_number },
			page_no: 1,
			page_size: 1
		});
		const d = res.dataArray[0];
		d.depts = fd.data.depts;
		render(fd, d, P01, 'P01', 'inner');
		curr_content_node = fd.data.node.querySelector("#" + fd.data.content) as HTMLElement;
		curr_content_node.classList.add('display-n');
		new_content_node = fd.data.node.querySelector("#c4") as HTMLElement;
		curr_content_node.classList.remove('display-n');
		fd.data.content = 'c4';
	}
}
